import fs from 'fs'
import path from 'path'
import { ActionFunction, json } from 'remix'

export const action: ActionFunction = async ({ request, params }) => {
    const root = path.join(process.cwd(), 'tasks')
    const form = await request.formData()
    const filename = form.get('filename') as string
    const fullpath = path.join(root, filename)
    const content = JSON.parse(fs.readFileSync(fullpath, 'utf8'))

    return json({ success: true, data: content })
}
